#!/bin/sh

TARGET=TouchRemocon
VERSION=`grep Version control | cut -f2 -d ' '`
ARCH=iphoneos-arm

mkdir -p $TARGET.app
# mv $TARGET $TARGET.app/
rm -rf $TARGET.app/.svn
rm -rf $TARGET.app/Japanese.lproj/.svn

chmod -R +r $TARGET.app
chmod +x $TARGET.app
chmod +x $TARGET.app/${TARGET}
chmod +x $TARGET.app/${TARGET}_

# rm ${TARGET}_${VERSION}.zip
# zip -r ${TARGET}_${VERSION}.zip $TARGET.app

# source tar
mkdir -p $TARGET
cp *.m *.h Makefile $TARGET
rm ${TARGET}_${VERSION}_src.tar.gz
tar czf ${TARGET}_${VERSION}_src.tar.gz $TARGET
rm -rf $TARGET

# make cydia package(dpkg)
mkdir -p $TARGET
mkdir -p $TARGET/DEBIAN
mkdir -p $TARGET/Applications

cp -R $TARGET.app $TARGET/Applications
cp control $TARGET/DEBIAN

rm ${TARGET}_${VERSION}_${ARCH}.deb
dpkg-deb -b $TARGET
mv $TARGET.deb ${TARGET}_${VERSION}_${ARCH}.deb

rm -rf $TARGET

# generate Packages for Debian repository
cp control Packages
echo Filename: ./${TARGET}_${VERSION}_${ARCH}.deb >>Packages
echo Size: `du -b ${TARGET}_${VERSION}_${ARCH}.deb | cut -f1` >>Packages
echo MD5sum: `md5sum ${TARGET}_${VERSION}_${ARCH}.deb | cut -f1 -d ' '` >>Packages
rm Packages.gz
gzip -c9 Packages >Packages.gz
rm Packages
